from flask import Blueprint

# 创建蓝图对象
admin_blue = Blueprint("admin", __name__, url_prefix="/admin")

# 让视图函数与主程序建立联系
from info.modules.admin.views import *


# 蓝图设置请求钩子：只会监听该蓝图注册的路由
@admin_blue.before_request
def check_superuser():
    is_admin = session.get("is_admin")
    if not is_admin and not request.url.endswith(url_for("admin.login")):
        # 未登录并且不是访问后台登陆路由
        return redirect(url_for("home.index"))
